<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			.box {
				width: 200px;
				height: 200px;
				position: relative;
				margin: 100px auto;
				background-color: red;
			}
		</style>
	</head>
	<body>
		<div class="box"></div>
		<script type="text/javascript">
			//获取用户在盒子内点击的坐标
			var box = document.querySelector(".box");
			box.addEventListener("mousemove", function(e) {
				console.log(box.offsetTop + " " + e.pageY);
				console.log(box.offsetLeft + " " + e.pageX);
				var innerX = e.pageX - box.offsetLeft;
				var innerY = e.pageY - box.offsetTop;
				box.innerHTML = "X坐标:" + innerX + " Y坐标:" + innerY;
			})
		</script>
	</body>
</html>
